import java.util.Stack;

public class MinStack {

    private Stack<Integer> A, B;

    /**
     * initialize your data structure here.
     */
    public MinStack() {
        A = new Stack<>();
        B = new Stack<>();
    }

    public void push(int x) {
        A.add(x);
        if (B.isEmpty()) {
            B.add(x);
        } else {
            int topVal = B.peek();
            if (x <= topVal) {
                B.push(x);
            }
        }
    }

    public void pop() {
        int peekA = A.peek();
        if (peekA == B.peek()) {
            B.pop();
        }
        A.pop();
    }

    public int top() {
        return A.peek();
    }

    public int min() {
        return B.peek();
    }

}
